From fe553b82d2bf2ce5a76a571cedb4b1e0389cfc99 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Sat, 31 Mar 2012 03:47:06 +0100 Subject: [PATCH] use optimized powf for x^(1.0/2.4) --- babl/base/util.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/babl/base/util.h b/babl/base/util.h index 7ccaf8f..bca25eb 100644 --- a/babl/base/util.h +++ b/babl/base/util.h @@ -56,12 +56,29 @@ #ifdef BABL_USE_SRGB_GAMMA +/* fast approximation of x ^ (5/12) from a response by David Hammen at + * http://stackoverflow.com/questions/6475373/optimizations-for-pow-with-const-non-integer-exponent/6475516#6475516 + * + */ +static inline double xpow512 (double x) +{ + double cbrtx = cbrt(x); + return cbrtx*sqrt(sqrt(cbrtx)); +} + + static inline double linear_to_gamma_2_2 (double value) { +#if 0 if (value > 0.0030402477F) return 1.055F * pow (value, (1.0F/2.4F)) - 0.055F; return 12.92F * value; +#else + if (value > 0.0030402477F) + return 1.055F * xpow512 (value) - 0.055F; + return 12.92F * value; +#endif } static inline double -- 2.30.2